<extend name="Public/layout"/>

<block name="body">
    <div class="title">
        <h2>{$meta_title}</h2>
    </div>
    <div class="row toolbar">
        <div class="col-xs-12">
            <ul class="nav nav-pills">
                <volist name="Think.config.CONFIG_GROUP_LIST" id="config_group">
                    <li class="<php>if($current_group == $key) echo 'active';</php>"><a href="{:u('group', array('group' => $key))}">{$config_group}</a></li>
                </volist>
            </ul>
        </div>
    </div>
    <form action="{:U('save')}" method="post" class="form">
        <volist name="list" id="config">
            <div class="form-group">
                <label class="item-label">{$config.title}<span class="check-tips">（{$config.remark}）</span></label>
                <div class="controls config">
                    <switch name="config.type">
                        <case value="0">
                            <input type="text" class="form-control" name="config[{$config.name}]" value="{$config.value}">
                        </case>
                        <case value="1">
                            <input type="text" class="form-control" name="config[{$config.name}]" value="{$config.value}">
                        </case>
                        <case value="2">
                            <textarea name="config[{$config.name}]" class="form-control">{$config.value}</textarea>
                        </case>
                        <case value="3">
                            <textarea name="config[{$config.name}]" class="form-control">{$config.value}</textarea>
                        </case>
                        <case value="4">
                            <select name="config[{$config.name}]" class="form-control">
                                <volist name=":parse_config_attr($config['extra'])" id="vo">
                                    <option value="{$key}" <eq name="config.value" value="$key">selected</eq>>{$vo}</option>
                                </volist>
                            </select>
                        </case>
                        <case value="5">
                            <div id="upload"></div>
                            <div id="preview">
                                <input type="hidden" name="config[{$config.name}]" value="{$config.value}">
                                <img style="margin-top:8px;max-height:120px;" src="{$config.value|get_cover}">
                            </div>
                            <link rel="stylesheet" type="text/css" href="__PUBLIC__/huploadify/huploadify.css">
                            <script type="text/javascript" src="__PUBLIC__/huploadify/huploadify.js" charset="utf-8"></script>
                            <script type="text/javascript">
                                $('#upload').Huploadify({
                                    fileTypeExts:'*.jpg;*.png;*.gif',//允许上传的文件类型，格式'*.jpg;*.doc'
                                    uploader:'{:U("Upload/upload")}',//文件提交的地址
                                    auto:true,//是否开启自动上传
                                    multi:false,//是否允许选择多个文件
                                    formData:{dir:'image'},//发送给服务端的参数，格式：{key1:value1,key2:value2}
                                    buttonText:'上 传 图 片',//上传按钮上的文字
                                    onUploadComplete:function(file, data){
                                        var data = $.parseJSON(data);
                                        $('#preview img').attr('src', data.url);
                                        $('#preview input').attr('value', data.id);
                                    },
                                    onUploadError:function(){
                                        console.log('开始失败');
                                    },
                                    onInit:function(){
                                        console.log('初始化');
                                    },
                                    onCancel:function(file){
                                        console.log(file);
                                    }
                                });
                            </script>
                        </case>
                        <case value="6">
                            <textarea name="config[{$config.name}]" class="form-control" id="{$config.name}">{$config.value}</textarea>
                            <script type="text/javascript">
                                var editor_{$config.name};
                                KindEditor.ready(function(K) {
                                    editor_{$config.name} = K.create('#{$config.name}', {
                                        allowFileManager : false,
                                        themesPath: K.basePath,
                                        height: '200px',
                                        resizeType: 1,
                                        pasteType : 2,
                                        urlType : 'absolute',
                                        items : [
                                            'fontname', 'fontsize', '|',
                                            'forecolor', 'hilitecolor', 'bold','italic', 'underline', 'removeformat','|',
                                            'justifyleft', 'justifycenter', 'justifyright','justifyfull', 'insertorderedlist', 'insertunorderedlist', '|',
                                            'emoticons', 'image', 'table', 'baidumap', 'link', 'unlink'
                                        ],
                                        fileManagerJson : '{:U("Upload/file_manager")}',
                                        uploadJson : '{:U("Upload/upload")}',
                                        remoteImgSaveUrl: '{:U("Upload/download")}',
                                        extraFileUploadParams: {
                                            session_id : '{:session_id()}'
                                        },
                                        afterBlur: function(){this.sync();}
                                    });
                                });
                            </script>
                        </case>
                    </switch>
                </div>
            </div>
        </volist>
        <div class="form-group">
            <div class="controls">
                <empty name="list">
                    <button type="submit" disabled class="btn disabled" target-form="form">确 定</button>
                <else/>
                    <button type="submit" class="btn ajax-post" target-form="form">确 定</button>
                </empty>
                <button class="btn btn-return" onclick="javascript:history.back(-1);return false;">返 回</button>
            </div>
        </div>
    </form>
</block>
